package com.fencing_squad.homo.slice;

import com.fencing_squad.homo.ResourceTable;
import com.fencing_squad.homo.util.AnimationConfig;
import com.fencing_squad.homo.util.Data;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;

public class GuideSlice extends AbilitySlice {
    Component loginButton;
    Text registerButton;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent((ComponentContainer) LayoutScatter.getInstance(this).parse(ResourceTable.Layout_login_main, null, false));
        initConfig();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    private void initConfig() {
        loginButton = findComponentById(ResourceTable.Id_loginButton);
        registerButton = (Text) findComponentById(ResourceTable.Id_registerButton);

        AnimationConfig.setClickAnimation(loginButton, getContext(), ResourceTable.Graphic_button_clicked, ResourceTable.Graphic_button);
        AnimationConfig.setClickAnimation(registerButton, AnimationConfig.THEME_COLOR_DARK, AnimationConfig.THEME_COLOR);
        loginButton.setClickedListener(this::login);
        registerButton.setClickedListener(this::register);
    }

    private void login(Component component) {
        presentForResult(new LoginSlice(), new Intent(), 0);
    }

    @Override
    protected void onResult(int requestCode, Intent resultIntent) {
        super.onResult(requestCode, resultIntent);
        if(Data.Account.isLogin) {
            terminate();
        }
    }

    private void register(Component component) {

    }
}
